package com.programmercarl.greed;

/**
 * https://leetcode.cn/problems/jump-game/description/
 * 跳跃游戏Ⅱ  参考
 *
 * @author yulongtian
 * @create 2025-02-06 16:50
 */
public class Test06 {
    public static void main(String[] args) {
        Test06 test06 = new Test06();
        System.out.println(test06.jump(new int[]{7, 0, 9, 6, 9, 6, 1, 7, 9, 0, 1, 2, 9, 0, 3}));
    }

    public int jump(int[] nums) {
        if (nums.length == 1) {
            return 0;
        }
        int curPoint = 0;
        int nextPoint = 0;
        int ans = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            nextPoint = Math.max(i + nums[i], nextPoint);
            if (i == curPoint) {
                curPoint = nextPoint;
                ans++;
            }
        }
        return ans;
    }

}
